const STATUS = {
  1: '投保失败',
  2: '投保成功'
}
import axios from '@/utils/request'
export default {
  InsuranceRecord: {
    form: {
      fields: [
        'id',
        'user',
        'staff',
        'insurance',
        'status',
        'extraData'
      ]
    },
    list: {
      query: {
        '@expands': `['entity.staff']`,
        '@order': `entity.createdTime|DESC`
      },
      list_filter: {
        status: Object.assign({ __label: '状态' }, STATUS),
        beforeCreatedTime: {
          expression: 'entity.getCreatedTime() >= datetime.get(":value  00:00:00")',
          label: '开始时间',
          type: 'date'
        },
        afterCreatedTime: {
          expression: 'entity.getCreatedTime() < datetime.get(":value 23:59:59")',
          label: '结束时间',
          type: 'date'
        },
        'staff.store.id': () => {
          return axios
            .get(`/manage/stores`)
            .then(res =>
              Object.assign({ __label: '门店' },
                ...res.data.map(v => { return { [v.id]: v.name } })))
        },
      },
      list_display: [
        'id',
        'user',
        'staff',
        {
          property: 'staff.__metadata.store.__toString',
          label: '门店'
        },
        {
          property: 'extraData',
          label: '投保信息',
          component: {
            props: ['data'],
            render(h) {
              if (this.data) {return <div>
                <div>{this.data.insuredInfos[0].name}</div>
                <div>{this.data.insuredInfos[0].employeeList[0].name}</div>
                <div>{this.data.insuredInfos[0].employeeList[0].idCode}</div>
              </div>
              } else {
                return <div>无</div>
              }
            }
          }
        },
        'insurance',
        {
          property: 'status',
          label: '投保状态',
          component: {
            props: ['data'],
            render(h) {
              if (this.data === 1) {
                return <div><el-tag type='danger'>投保失败</el-tag></div>
              } else {
                return <div><el-tag type='success'>投保成功</el-tag></div>
              }
            }
          }
        },
        'createdTime'
      ]
    }
  }
}

